package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.dao.RequestDao;
import com.rmt.www.dao.TestArtifactRequestDao;
import com.rmt.www.vo.Request;
import com.rmt.www.vo.TestArtifactRequest;

public class TestArtifactRequestDaoImpl implements TestArtifactRequestDao {

	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	public void deleteTestArtifactRequestByRId(int rid) {
		this.jdbcTemplate.update("update testartifactrequest set status='deleted' where id=?", new Object[]{rid}, new int[]{java.sql.Types.INTEGER});
	}

	public TestArtifactRequest getTestArtifactRequestByRId(int rid) {
		return (TestArtifactRequest) this.jdbcTemplate.queryForObject("select* from testartifactrequest where id=? and status!='deleted'", 
				new Object[]{rid}, new TestArtifactRequestRowMapper());
	}

	@SuppressWarnings("unchecked")
	public List<TestArtifactRequest> getTestArtifactRequestsByPId(int pid) {
		return this.jdbcTemplate.query("select * from testartifactrequest where pid=? and status!='deleted'", 
				new Object[]{pid}, new int[]{java.sql.Types.INTEGER}, new TestArtifactRequestRowMapper());
	}

	public void insertTestArtifactRequest(TestArtifactRequest request) {
		jdbcTemplate.update("insert into testartifactrequest(pid,testcasetype,title,priority,precondition,input,testdata,steps,expectedresult,postcondition,effort,cost,risk,comment,createrid,createdtime,updaterid,updatedtime,updatedtimes,version,status,testartifactid,requesttype) " +
			"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
	new Object[]{
				request.getPid(),
				request.getTestcasetype(),
				request.getTitle(),
				request.getPriority(),
				request.getPrecondition(),
				request.getInput(),
				request.getTestdata(),
				request.getSteps(),
				request.getExpectedresult(),
				request.getPostcondition(),
				request.getEffort(),
				request.getCost(),
				request.getRisk(),
				request.getComment(),
				request.getCreaterid(),
				request.getCreatedtime(),
				request.getUpdaterid(),
				request.getUpdatedtime(),
				request.getUpdatedtimes(),
				request.getVersion(),
				request.getStatus(),
				request.getTestartifactid(),
				request.getRequestType()
	},new int[] {
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.INTEGER,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR
	});
	}

	

}
